package o;

import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.content.res.Resources.NotFoundException;
import android.content.res.Resources.Theme;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Build.VERSION;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.util.TypedValue;
import androidx.annotation.ColorInt;
import androidx.annotation.ColorRes;
import androidx.annotation.DrawableRes;
import androidx.annotation.FontRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;
import androidx.core.content.res.FontResourcesParserCompat;
import androidx.core.content.res.FontResourcesParserCompat.c;

public final class fv {

    public static abstract class d {
        public abstract void ˋ(int i);

        public abstract void ˎ(@NonNull Typeface typeface);

        @RestrictTo({androidx.annotation.RestrictTo.d.ॱ})
        public final void ˋ(final Typeface typeface, @Nullable Handler handler) {
            if (handler == null) {
                handler = new Handler(Looper.getMainLooper());
            }
            handler.post(new Runnable(this) {
                final /* synthetic */ d ॱ;

                public void run() {
                    this.ॱ.ˎ(typeface);
                }
            });
        }

        @RestrictTo({androidx.annotation.RestrictTo.d.ॱ})
        public final void ˊ(final int i, @Nullable Handler handler) {
            if (handler == null) {
                handler = new Handler(Looper.getMainLooper());
            }
            handler.post(new Runnable(this) {
                final /* synthetic */ d ˎ;

                public void run() {
                    this.ˎ.ˋ(i);
                }
            });
        }
    }

    @Nullable
    public static Drawable ॱ(@NonNull Resources resources, @DrawableRes int i, @Nullable Theme theme) throws NotFoundException {
        if (VERSION.SDK_INT >= 21) {
            return resources.getDrawable(i, theme);
        }
        return resources.getDrawable(i);
    }

    @ColorInt
    public static int ˏ(@NonNull Resources resources, @ColorRes int i, @Nullable Theme theme) throws NotFoundException {
        if (VERSION.SDK_INT >= 23) {
            return resources.getColor(i, theme);
        }
        return resources.getColor(i);
    }

    @Nullable
    public static ColorStateList ˊ(@NonNull Resources resources, @ColorRes int i, @Nullable Theme theme) throws NotFoundException {
        if (VERSION.SDK_INT >= 23) {
            return resources.getColorStateList(i, theme);
        }
        return resources.getColorStateList(i);
    }

    @Nullable
    public static Typeface ˎ(@NonNull Context context, @FontRes int i) throws NotFoundException {
        if (context.isRestricted()) {
            return null;
        }
        return ॱ(context, i, new TypedValue(), 0, null, null, false);
    }

    public static void ॱ(@NonNull Context context, @FontRes int i, @NonNull d dVar, @Nullable Handler handler) throws NotFoundException {
        hf.ˊ(dVar);
        if (context.isRestricted()) {
            dVar.ˊ(-4, handler);
            return;
        }
        ॱ(context, i, new TypedValue(), 0, dVar, handler, false);
    }

    @RestrictTo({androidx.annotation.RestrictTo.d.ॱ})
    public static Typeface ˋ(@NonNull Context context, @FontRes int i, TypedValue typedValue, int i2, @Nullable d dVar) throws NotFoundException {
        if (context.isRestricted()) {
            return null;
        }
        return ॱ(context, i, typedValue, i2, dVar, null, true);
    }

    private static Typeface ॱ(@NonNull Context context, int i, TypedValue typedValue, int i2, @Nullable d dVar, @Nullable Handler handler, boolean z) {
        Resources resources = context.getResources();
        resources.getValue(i, typedValue, true);
        Typeface ˋ = ˋ(context, resources, typedValue, i, i2, dVar, handler, z);
        if (ˋ != null || dVar != null) {
            return ˋ;
        }
        throw new NotFoundException("Font resource ID #0x" + Integer.toHexString(i) + " could not be retrieved.");
    }

    private static Typeface ˋ(@NonNull Context context, Resources resources, TypedValue typedValue, int i, int i2, @Nullable d dVar, @Nullable Handler handler, boolean z) {
        if (typedValue.string == null) {
            throw new NotFoundException("Resource \"" + resources.getResourceName(i) + "\" (" + Integer.toHexString(i) + ") is not a Font: " + typedValue);
        }
        String charSequence = typedValue.string.toString();
        if (charSequence.startsWith("res/")) {
            Typeface ˏ = ft.ˏ(resources, i, i2);
            if (ˏ == null) {
                try {
                    if (charSequence.toLowerCase().endsWith(".xml")) {
                        c ˎ = FontResourcesParserCompat.ˎ(resources.getXml(i), resources);
                        if (ˎ != null) {
                            return ft.ˏ(context, ˎ, resources, i, i2, dVar, handler, z);
                        }
                        Log.e("ResourcesCompat", "Failed to find font-family tag");
                        if (dVar != null) {
                            dVar.ˊ(-3, handler);
                        }
                        return null;
                    }
                    ˏ = ft.ˏ(context, resources, i, charSequence, i2);
                    if (dVar == null) {
                        return ˏ;
                    }
                    if (ˏ != null) {
                        dVar.ˋ(ˏ, handler);
                        return ˏ;
                    }
                    dVar.ˊ(-3, handler);
                    return ˏ;
                } catch (Throwable e) {
                    Log.e("ResourcesCompat", "Failed to parse xml resource " + charSequence, e);
                    if (dVar != null) {
                        dVar.ˊ(-3, handler);
                    }
                    return null;
                } catch (Throwable e2) {
                    Log.e("ResourcesCompat", "Failed to read xml resource " + charSequence, e2);
                    if (dVar != null) {
                        dVar.ˊ(-3, handler);
                    }
                    return null;
                }
            } else if (dVar == null) {
                return ˏ;
            } else {
                dVar.ˋ(ˏ, handler);
                return ˏ;
            }
        }
        if (dVar != null) {
            dVar.ˊ(-3, handler);
        }
        return null;
    }
}
